/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Conexion;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Sebastian
 */
public class Cliente {

    Socket socket;
    InputStream entrada;
    OutputStream salida;
    DataInputStream entradaDatos;
    DataOutputStream salidaDatos, salidaDatos2;

    public Cliente() {
        try {
            this.socket = new Socket("localhost", 5000);
        } catch (Exception Error) {
            System.out.println("Error" + Error);
        }
    }

    public void enviar(int x, int y, int dir) {
        if (!this.socket.isClosed()) {
            try {
                salida = socket.getOutputStream();//canal de comunicacion q envia al cliente
                salidaDatos = new DataOutputStream(salida);//envio informacion
                salidaDatos.writeInt(x);
                salidaDatos.writeInt(y);
                salidaDatos.writeInt(dir);
            } catch (Exception Error) {
                System.out.println("Error" + Error);
            }
        }
        else{
            this.reConexion();
        }
    }
    
    public void reConexion(){
        try {
            this.socket = new Socket("10.6.77.95", 5000);
        } catch (Exception Error) {
            System.out.println("Error" + Error);
        }
    }
}